package com.dq.domain.org;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;

/**
 * @author liuhui
 * @date 2019/11/20 0020 10:52:31
 */
@Data
@Entity
@ApiModel("门店顾客等级设置")
public class OrgCustomerLevel extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("门店")
    @ManyToOne
    protected Org sysDept;

    @ApiModelProperty("等级名称")
    protected String levenName;

    @ApiModelProperty("该等级满足最低消费金额")
    protected BigDecimal minAmount;

    @ApiModelProperty("该等级满足最高消费金额")
    protected BigDecimal maxAmount;


    @Data
    @ApiModel(value = "门店顾客等级设置视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        protected Long id;

        @ApiModelProperty("等级名称")
        protected String levenName;

        @ApiModelProperty("最小金额")
        protected BigDecimal minAmount;

        @ApiModelProperty("最大金额")
        protected BigDecimal maxAmount;

        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.levenName = fmt(this.getLevenName());
        vo.minAmount = fmt(this.getMinAmount());
        vo.maxAmount = fmt(this.getMaxAmount());

        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);

        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();
        return vo;
    }

    @Data
    @ApiModel("等级返回实体")
    public static class levelVo{
        @ApiModelProperty("id")
        protected Long id;

        @ApiModelProperty("等级名称")
        protected String levelName;

        @ApiModelProperty("最小金额")
        protected BigDecimal minAmount;

        @ApiModelProperty("最大金额")
        protected BigDecimal maxAmount;
    }

    public levelVo tolevelVo(){
        levelVo vo = new levelVo();
        vo.id = this.getId();
        vo.levelName = fmt(this.getLevenName());
        vo.minAmount = fmt(this.getMinAmount());
        vo.maxAmount = fmt(this.getMaxAmount());
        return vo;
    }
}
